package main;

import java.io.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {

	public static void main(String[] args) throws IOException {

		FileInputStream fstream = new FileInputStream("textfile.txt");
		// Get the object of DataInputStream
		DataInputStream in = new DataInputStream(fstream);
		BufferedReader br = new BufferedReader(new InputStreamReader(in));

		String strLine;
		// Read File Line By Line
		int nrLinie = 0;
		while ((strLine = br.readLine()) != null) {

			Pattern sablon = Pattern.compile(".*<h4>.*");
			Pattern sablon2 = Pattern.compile(".*to.*");
			Pattern sablon3 = Pattern.compile("    .*");
			Pattern sablon4 = Pattern.compile(".*</.*");

			Matcher potrivire = sablon.matcher(strLine);
			Matcher potrivire2 = sablon2.matcher(strLine);
			Matcher potrivire3 = sablon3.matcher(strLine);
			Matcher potrivire4 = sablon4.matcher(strLine);

			if (potrivire.matches()) {

				System.out.println("<h4> \tLinia:" + nrLinie + "       "
						+ strLine);
			} else {
				if (potrivire2.matches()) {

					System.out.println("to \tLinia:" + nrLinie + "       "
							+ strLine);
				} else {
					if (potrivire3.matches()) {

						System.out.println("4sp \tLinia:" + nrLinie + "       "
								+ strLine);
					} else {
						if (potrivire4.matches()) {

							System.out.println("</ \tLinia:" + nrLinie
									+ "       " + strLine);
						}
					}
				}
			}
			nrLinie++;

		}
		System.out.println();
		fstream = new FileInputStream("textfile.txt");
		// Get the object of DataInputStream
		in = new DataInputStream(fstream);
		br = new BufferedReader(new InputStreamReader(in));

		while ((strLine = br.readLine()) != null) {

			Pattern sablon = Pattern.compile(".*<p.*");
			Pattern sablon2 = Pattern.compile(".*</p>.*");
			Pattern sablon3 = Pattern.compile(".*\"line\".*");

			Matcher potrivire = sablon.matcher(strLine);
			Matcher potrivire2 = sablon2.matcher(strLine);
			Matcher potrivire3 = sablon3.matcher(strLine);
			
			/*if (potrivire.matches()) {
				System.out.println(potrivire.replaceAll("<span"));
			} else {
				if (potrivire2.matches()) {
					System.out.println(potrivire2.replaceAll("</span>"));
				} else if (potrivire3.matches()) {
					System.out.println(potrivire3.replaceAll("\"sentence\""));
				} else {
					System.out.println(strLine);
				}
			}*/

			 System.out.println(strLine.replaceAll("<p", "<span")
			 .replaceAll("</p>", "</span>")
			 .replaceAll("\"line\"", "\"sentence\""));
		}

	}

}
